Page({
  data: {
    dialogVisible: false,
    isShow: true,
    roomLists: [],
    statusList: ['正在审核', '审核通过', '审核失败'],
    statuslist: ['info', 'success', 'fail'],
    id: '',
  },
  async onShow() {
    const { data } = await wx.http.get('/room')

    this.setData({
      roomLists: data,
    })
    this.setData({
      isShow: this.data.roomLists.length > 0,
    })
    console.log(this.data.roomLists)
  },

  swipeClose(ev) {
    this.setData({
      id: ev.currentTarget.dataset.id,
    })
    const { position, instance } = ev.detail

    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })

      // swiper-cell 滑块关闭
      instance.close()
    }
  },

  goDetail(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/house_pkg/pages/detail/index?id=${id}`,
    })
  },

  addHouse() {
    if (this.data.roomLists.length === 6) wx.utils.toast('房屋信息已达上限！')
    else {
      wx.navigateTo({
        url: '/house_pkg/pages/locate/index',
      })
    }
  },
  async dialogClose() {
    const { code } = await wx.http.delete(`/room/${this.data.id}`)
    console.log(code)
    wx.utils.toast('删除成功!')
    this.onShow()
  },
})
